package com.pretty.test.controller.pets.station;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pretty.test.controller.pets.station.dto.StationPageDTO;
import com.pretty.test.controller.pets.station.vo.StationListVO;
import com.pretty.test.controller.pets.station.vo.StationPageVO;
import com.pretty.test.entity.PetsStation;
import com.pretty.test.service.IPetsStationService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 驿站控制器
 * @author dujianyu
 * @since 2021-04-02
 */
@RestController
@AllArgsConstructor
@RequestMapping("/station")
public class PetsStationController {

    private IPetsStationService service;

    /**
     * 自定义分页
     * @param page
     * @param dto
     */
    @GetMapping("/page")
    public R<IPage<StationPageVO>> page(Page<StationPageVO> page, StationPageDTO dto){
        return R.ok(service.selectStationPage(page,dto));
    }

    /**
     * 新增或修改
     * @param petsStation
     */
    @PostMapping("/submit")
    public  R<Boolean> submit(@RequestBody PetsStation petsStation){
        return R.ok(service.saveOrUpdate(petsStation));
    }

    /**
     * 逻辑删除
     * @param id
     */
    @PostMapping("/delete")
    public R<Boolean> delete(String id){
        return R.ok(service.removeById(id));
    }

    /**
     * 首页获得驿站列表
     */
    @GetMapping("/getStationList")
    public R<List<StationListVO>> getStationList(String stationName){
        return R.ok(service.getStationList(stationName));
    }

}
